# -*- coding:utf-8 -*-
from heuristics.sqr_min import *
from heuristics.Obst_Distance import *
from search.all import *
from multi_robot_problem import MultiRobotState
from time import *
"""
Created on Apr 11, 2011

@author: bob
"""
#Kirshon Part
def createProblem():
    # First Problem - Easy

    robots = tuple([(9,0),(9,3)])
    
    dirt_locations = set()
    dirt_locations.add((0,1))
    dirt_locations.add((0,3))

    obstacle_locations = set()
    obstacle_locations.add((0,2))
    obstacle_locations.add((1,1))
    obstacle_locations.add((1,2))
    obstacle_locations.add((2,1))
    obstacle_locations.add((8,0))
    obstacle_locations.add((8,1))
    obstacle_locations.add((8,3))
    obstacle_locations.add((5,0))
    obstacle_locations.add((5,2))
    obstacle_locations.add((5,3))
    
    return MultiRobotState(10, 4, robots, frozenset(dirt_locations), frozenset(obstacle_locations))



algo2 = BestFirstAnyTimeGraphSearch()
algo1 = BestFirstGraphSearch()
algo3 = AStarAnytime()
gbf = BestFirstGraphSearch()
width = 15
height = 15
robots = ((8,1),(2,3),(8,8),(5,5),(11,12))
dirt_locations = frozenset([(7,8),(7,1),(1,1),(2,5),(9,9),(5,2),(10,14)])
obstacles = frozenset([(0,4),(1,4),(2,4),(3,4),(4,4),(5,4),(6,4)])
#problem = MultiRobotState(width, height, robots, dirt_locations, obstacles)
problem = createProblem()
print "~~~~~The problem:~~~~~"
print problem
#########################

print "Anytime Algorithm:"
obj = algo2.find(problem, Pile_Division(problem),78)
print obj
if not obj is None:
    print "success"
#    start = clock()
#    obj = algo1.find(problem, Manhattan())
#    end = clock()
#    minutes = int((end - start) / 60)
#    print "Greedy:"
#    print minutes, (end-start) - minutes*60  
#    print obj
#    print "Length of solution: " , len(obj)
else:
    print "not enough time!"

#astarAnySol,sols = algo3.find(problem, Manhattan(), 60*2)
#if not (astarAnySol is None):
#    for node in astarAnySol.getPath():
#        print node
#    print "#solutions:",len(sols)
#    i = 0
#    for sol in sols:
#        print "sol ",i,":", len(sol.getPathActions())
#        i = i + 1
#else:
#    print "No solutions found!"
'''
sol = gbf.find(problem, Pile_Division(problem))
print len(sol),sol
'''